#pragma once

#include "Feature.h"

#include "Classifier.h"

namespace uml {

const bool Feature::isStatic_default_ = false;
Feature::Feature(const QString& umlType)
    : NamedElement(umlType) {}

void Feature::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    NamedElement::fromJson(json, errorList);
    RedefinableElement::fromJson(json, errorList);
    featuringClassifier_ = JsonSerializable::create<Classifier>(json.value("featuringClassifier"), errorList);

    isStatic_ = json.value("isStatic").toBool(isStatic_default_);
}

void Feature::toJson(QJsonObject& json) {
    NamedElement::toJson(json);
    RedefinableElement::toJson(json);
    if (featuringClassifier_) {
        QJsonObject featuringClassifier_json;
        featuringClassifier_->toJson(featuringClassifier_json);
        json.insert("featuringClassifier", featuringClassifier_json);
    }
    if (isStatic_ != isStatic_default_) {
        json.insert("isStatic", isStatic_);
    }
}

/// <summary>
/// featuringClassifier getter
/// The Classifiers that have this Feature as a feature.
/// </summary>
shared_ptr<Classifier> Feature::featuringClassifier() const {
    return featuringClassifier_;
}

/// <summary>
/// featuringClassifier setter
/// The Classifiers that have this Feature as a feature.
/// </summary>
void Feature::setFeaturingClassifier(shared_ptr<Classifier> value) {
    featuringClassifier_ = value;
}

/// <summary>
/// isStatic getter
/// Specifies whether this Feature characterizes individual instances classified by
/// the Classifier (false) or the Classifier itself (true).
/// </summary>
bool Feature::isStatic() const {
    return isStatic_;
}

/// <summary>
/// isStatic setter
/// Specifies whether this Feature characterizes individual instances classified by
/// the Classifier (false) or the Classifier itself (true).
/// </summary>
void Feature::setIsStatic(bool value) {
    isStatic_ = value;
}

} // namespace uml
